/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Comparator;

/**
 * <p>Project: javase202202 - Arr7
 * <p>Powered by Lisi On 2022-06-06 09:57:02
 * <p>Created by IntelliJ IDEA
 *

 * @version 1.0
 * @since 17
 */
public class Arr7 {
    public static void main(String[] args) {
        var lang = new String[]{"java", "c", "go", "python", "javascript", "A", "c++"};
        System.out.println(Arrays.toString(lang));
        //升序
        Arrays.sort(lang);
        System.out.println(Arrays.toString(lang));
        //降序
        Arrays.sort(lang, Comparator.reverseOrder());
        System.out.println(Arrays.toString(lang));
        //乱序
        Arrays.sort(lang, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(lang, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(lang, (a, b) -> Math.random() > .5 ? 1 : -1);
        Arrays.sort(lang, (a, b) -> Math.random() > .5 ? 1 : -1);
        System.out.println(Arrays.toString(lang));

        //按字符串长度排序
        //升序
        Arrays.sort(lang,(a,b)->a.length()-b.length());
        System.out.println(Arrays.toString(lang));
        //降序
        Arrays.sort(lang,(a,b)->b.length()-a.length());
        System.out.println(Arrays.toString(lang));
    }
}
